using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace Galplay {
  public static class Kit {
    public static bool IsEmpty(string str) {
      return str == null || str.Length == 0;
    }
    public static bool NotEmpty(string str) {
      return str != null && str.Length > 0;
    }


    public static string AutoCombine(string pre_path, string filename){
      if (IsEmpty(filename)) return filename;
      return Kit.NotEmpty(pre_path) ? Path.Combine(pre_path, filename) : filename;
    }

    /// <summary>
    /// 智能添加文件后缀名
    /// </summary>
    public static string AutoAddExtension(string fileName, string extension) {
      // 参数检查
      if (string.IsNullOrWhiteSpace(fileName)) { return fileName; }
      // 确保后缀以点开头
      if (!extension.StartsWith("."))
        extension = "." + extension;

      // 获取文件扩展名（系统方法自动处理路径中的点）
      string currentExt = Path.GetExtension(fileName);
      return string.IsNullOrEmpty(currentExt)
          ? fileName + extension
          : fileName;
    }
  }
}